package cn.jbolt.config.web;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 从类路径下的 META-INF/resources 目录和项目根目录下的 upload 文件夹中查找并提供静态资源。
 * 当客户端请求静态资源时，Spring MVC 会根据配置的路径去查找相应的文件并返回给客户端。
 */

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String userDir = System.getProperty("user.dir");
        String uploadPath = "file:" + userDir + "/upload/";
        registry.addResourceHandler("/**")
               .addResourceLocations("classpath:/META-INF/resources/", uploadPath);
    }
}